﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using JKF.Substructure;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace JKF.DataModule.SqlServerDAL
{
    /// <summary>
    /// 数据访问类dalPRODUCT_SORT。
    /// </summary>
   public partial class dalPRODUCT_SORT:IDAL.IdalPRODUCT_SORT
    {

        // 定义要获取哪些字段 SORT_KEY, NAME, TYPE, USER_CREATE, DATE_CREATE, DATE_UPDATE 
       private const string FieldShow = "SORT_KEY, NAME, TYPE, USER_CREATE, DATE_CREATE, DATE_UPDATE ";
        private const string FieldOrder = "NAME";
        private const string FieldKey = "SORT_KEY";
        /// <summary>
        /// 获取产品类别列表
        /// </summary>
        /// <param name="NAME">产品类别名称</param>
        /// <param name="pageCurrent">当前页码</param>
        /// <param name="pageSize">一页显示多少</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="rowCount">总记录数</param>
        /// <returns>返回DataTable数据</returns>
        public static DataTable GetProduct_SortsDAL(string NAME, int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
            var sql = new StringBuilder(@"  1=1 ");
            // 下面组装查询条件
            if (!string.IsNullOrEmpty(NAME))
            {
                sql.AppendFormat(" AND NAME  LIKE '%{0}%'", NAME);
            }
            // 下面调用此方法去查询数据库
            return DataPage.GetPageInfo("dbo.PRODUCT_SORT", FieldKey, pageCurrent, pageSize, FieldShow, FieldOrder, sql.ToString(), ref pageCount, ref rowCount).Tables[0];

        }
       /// <summary>
       /// 判断产品分类名称是否存在
       /// </summary>
       /// <param name="product_sort_name"></param>
       /// <returns></returns>
       public static bool ExistsProduct_SortNameDAL(string product_sort_name)
       {
           object obj = DB.HR.ExecuteScalar(CommandType.Text, "select count(1) from dbo.PRODUCT_SORT where NAME='" + product_sort_name + "'");
           return Convert.ToInt32(obj) > 0;
       }
       /// <summary>
       /// 事务删除产品分类
       /// </summary>
       /// <param name="shop_code">产品分类ID</param>
       /// <returns></returns>
       public static string TransactionSQLDeleteDAL(Guid sort_key)
       {
           int result = -1;
           Database db = DB.HR;
           DbCommand dbCommand = db.GetStoredProcCommand("[dbo].[proc_Product_SortDelete]");
           db.AddInParameter(dbCommand, "@sort_key", DbType.Guid, sort_key);
           db.AddOutParameter(dbCommand, "@result", DbType.Int32, result);
           db.ExecuteNonQuery(dbCommand);
           return dbCommand.Parameters["@result"].Value.ToString();
       }

       
    }
}
